//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "GaussKronrodAdaptive.h"
using namespace Cephei::QL::Math::Integrals;
#include <gen/QL/Math/Integrals/Integrator.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Integrals::CGaussKronrodAdaptive::CGaussKronrodAdaptive (Double tolerance, Microsoft::FSharp::Core::FSharpOption<UInt64>^ maxFunctionEvaluations) : CIntegrator(CGaussKronrodAdaptive::typeid)
{
    try
    {
#ifdef HANDLE
        _phGaussKronrodAdaptive = NULL;
#endif
        QuantLib::Real _tolerance = (QuantLib::Real)ValueHelper::Convert (tolerance);
        QuantLib::Size _maxFunctionEvaluations = 
            (Microsoft::FSharp::Core::FSharpOption<UInt64>::IsSome::get (maxFunctionEvaluations) ? (QuantLib::Size)ValueHelper::Convert (maxFunctionEvaluations->Value) : Null<QuantLib::Size>()); //4
        _ppGaussKronrodAdaptive = new boost::shared_ptr<QuantLib::GaussKronrodAdaptive> (new QuantLib::GaussKronrodAdaptive ( _tolerance,  _maxFunctionEvaluations ));
        SetIntegrator (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussKronrodAdaptive));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Integrals::CGaussKronrodAdaptive::CGaussKronrodAdaptive (boost::shared_ptr<QuantLib::GaussKronrodAdaptive>& childNative, Object^ owner) : CIntegrator(CGaussKronrodAdaptive::typeid)
{
#ifdef HANDLE
	_phGaussKronrodAdaptive = NULL;
#endif
	_ppGaussKronrodAdaptive = &childNative;
    _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussKronrodAdaptive));
}
Cephei::QL::Math::Integrals::CGaussKronrodAdaptive::CGaussKronrodAdaptive (QuantLib::GaussKronrodAdaptive& childNative, Object^ owner) : CIntegrator(CGaussKronrodAdaptive::typeid)
{
#ifdef HANDLE
	_phGaussKronrodAdaptive = NULL;
#endif
	_ppGaussKronrodAdaptive = new boost::shared_ptr<QuantLib::GaussKronrodAdaptive> (&childNative);
    _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussKronrodAdaptive));
    _GaussKronrodAdaptiveOwner = owner;
    _IntegratorOwner = owner;
}

Cephei::QL::Math::Integrals::CGaussKronrodAdaptive::CGaussKronrodAdaptive (CGaussKronrodAdaptive^ copy) : CIntegrator(CGaussKronrodAdaptive::typeid)
{
#ifdef HANDLE
	_phGaussKronrodAdaptive = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGaussKronrodAdaptive = new boost::shared_ptr<QuantLib::GaussKronrodAdaptive> (copy->GetShared());
        _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussKronrodAdaptive));
    }
}
Cephei::QL::Math::Integrals::CGaussKronrodAdaptive::CGaussKronrodAdaptive (System::Type^ t) : CIntegrator(CGaussKronrodAdaptive::typeid)
{
#ifdef HANDLE
	_phGaussKronrodAdaptive = NULL;
#endif
	if (!t->IsSubclassOf(CGaussKronrodAdaptive::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Integrals::CGaussKronrodAdaptive::CGaussKronrodAdaptive (QuantLib::Handle<QuantLib::GaussKronrodAdaptive>& childNative, Object^ owner)  : CIntegrator(CGaussKronrodAdaptive::typeid)
{
	_phGaussKronrodAdaptive = &childNative;
	_ppGaussKronrodAdaptive = &static_cast<boost::shared_ptr<QuantLib::GaussKronrodAdaptive>>(childNative.currentLink());
    _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussKronrodAdaptive));
    _GaussKronrodAdaptiveOwner = owner;
}
Cephei::QL::Math::Integrals::CGaussKronrodAdaptive::CGaussKronrodAdaptive (QuantLib::Handle<QuantLib::GaussKronrodAdaptive> childNative)  : CIntegrator(CGaussKronrodAdaptive::typeid)
{
	_phGaussKronrodAdaptive = &childNative;
	_ppGaussKronrodAdaptive = &static_cast<boost::shared_ptr<QuantLib::GaussKronrodAdaptive>>(childNative.currentLink());
    _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussKronrodAdaptive));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Integrals::CGaussKronrodAdaptive::CGaussKronrodAdaptive (QuantLib::GaussKronrodAdaptive childNative)  : CIntegrator(CGaussKronrodAdaptive::typeid)
{
#ifdef HANDLE
	_phGaussKronrodAdaptive = NULL;
#endif
	_ppGaussKronrodAdaptive = new boost::shared_ptr<QuantLib::GaussKronrodAdaptive> (new QuantLib::GaussKronrodAdaptive (childNative));
    _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussKronrodAdaptive));
}
#endif

Cephei::QL::Math::Integrals::CGaussKronrodAdaptive::~CGaussKronrodAdaptive ()
{
    if (_ppGaussKronrodAdaptive != NULL)
    {
	    delete _ppGaussKronrodAdaptive;
        _ppGaussKronrodAdaptive = NULL;
    }
}
Cephei::QL::Math::Integrals::CGaussKronrodAdaptive::!CGaussKronrodAdaptive ()
{
    if (_ppGaussKronrodAdaptive != NULL)
    {
	    delete _ppGaussKronrodAdaptive;
    }
}
QuantLib::GaussKronrodAdaptive& Cephei::QL::Math::Integrals::CGaussKronrodAdaptive::GetReference ()
{
    if (_ppGaussKronrodAdaptive == NULL) throw gcnew NativeNullException ();
	return **_ppGaussKronrodAdaptive;
}
boost::shared_ptr<QuantLib::GaussKronrodAdaptive>& Cephei::QL::Math::Integrals::CGaussKronrodAdaptive::GetShared ()
{
    if (_ppGaussKronrodAdaptive == NULL) throw gcnew NativeNullException ();
	return *_ppGaussKronrodAdaptive;
}
QuantLib::GaussKronrodAdaptive* Cephei::QL::Math::Integrals::CGaussKronrodAdaptive::GetPointer ()
{
    if (_ppGaussKronrodAdaptive == NULL) throw gcnew NativeNullException ();
	return &**_ppGaussKronrodAdaptive;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::GaussKronrodAdaptive>& Cephei::QL::Math::Integrals::CGaussKronrodAdaptive::GetHandle ()
{
	if (_phGaussKronrodAdaptive == NULL)
	{
		_phGaussKronrodAdaptive = new Handle<QuantLib::GaussKronrodAdaptive> (*_ppGaussKronrodAdaptive);
	}
	return *_phGaussKronrodAdaptive;
}
#endif
bool Cephei::QL::Math::Integrals::CGaussKronrodAdaptive::HasNative () 
{
	return (_ppGaussKronrodAdaptive != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Integrals::IGaussKronrodAdaptive^ Cephei::QL::Math::Integrals::CGaussKronrodAdaptive_Factory::Create (Double tolerance, Microsoft::FSharp::Core::FSharpOption<UInt64>^ maxFunctionEvaluations)
{
    return gcnew CGaussKronrodAdaptive ( tolerance,  maxFunctionEvaluations);
}
